#include "e2d/ui/GameManager.h"

e2d::GameManager::GameManager()
{



}

void e2d::GameManager::Init()
{
#ifdef E2D_BUILD_TRANS
	m_TransformHandler = std::make_shared<e2d::TransformHandler>();
#endif
#ifdef E2D_BUILD_RENDER

#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem = std::make_shared<e2d::AudioSystem>();
#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem = std::make_shared < e2d::PhysicsSystem>();
#endif
#ifdef E2D_BUILD_FUI

#endif

	m_SpriteRenderer = std::make_shared<e2d::SpriteRenderer>();

	m_ScriptSystem = std::make_shared<e2d::ScriptSystem>();

	m_PrefebManager = std::make_shared<e2d::PrefebManager>();
}


void e2d::GameManager::OnStart()
{
#ifdef E2D_BUILD_TRANS
	m_TransformHandler->OnStart();
#endif
#ifdef E2D_BUILD_RENDER
#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->OnStart();

#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem->OnStart();
#endif
#ifdef E2D_BUILD_FUI

#endif
	m_SpriteRenderer->OnStart();

	m_ScriptSystem->OnStart();

	m_PrefebManager->OnStart();

}

void e2d::GameManager::OnLoad()
{
	m_ScriptSystem->OnLoad();
	m_PrefebManager->OnLoad();

	m_SpriteRenderer->OnLoad();

#ifdef E2D_BUILD_TRANS
	m_TransformHandler->OnLoad();
#endif
#ifdef E2D_BUILD_RENDER
#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->OnLoad();
#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem->OnLoad();
#endif
#ifdef E2D_BUILD_FUI

#endif

}

void e2d::GameManager::OnLoadResources()
{


}
void e2d::GameManager::OnLoadPrefebs()
{
	m_PrefebManager->OnLoad();
}

void e2d::GameManager::OnLoadScripts()
{
}

void e2d::GameManager::OnRender()
{
	m_SpriteRenderer->OnRender();

}

void e2d::GameManager::OnRenderRuntime()
{
	m_SpriteRenderer->OnRenderRuntime();

}

void e2d::GameManager::OnUpdate()
{

#ifdef E2D_BUILD_TRANS
	m_TransformHandler->OnUpdate();
#endif
#ifdef E2D_BUILD_RENDER

#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->OnUpdate();
#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem->OnUpdate();
#endif
#ifdef E2D_BUILD_FUI

#endif

	m_ScriptSystem->OnUpdate();
	m_SpriteRenderer->OnUpdate();

}

void e2d::GameManager::OnUpdateRuntime()
{
#ifdef E2D_BUILD_TRANS
	m_TransformHandler->OnUpdateRuntime();
#endif
#ifdef E2D_BUILD_RENDER
	m_SpriteRenderer->OnUpdateRuntime();
#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->OnUpdateRuntime();
#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem->OnUpdateRuntime();
#endif
#ifdef E2D_BUILD_FUI

#endif

	m_ScriptSystem->OnUpdateRuntime();
	m_PrefebManager->OnUpdateRuntime();

}

void e2d::GameManager::OnDestory()
{

#ifdef E2D_BUILD_TRANS
	m_TransformHandler->OnDestory();
#endif
#ifdef E2D_BUILD_RENDER

#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->OnDestory();
#endif
#ifdef E2D_BUILD_PHYSICS

#endif
#ifdef E2D_BUILD_FUI

#endif

	m_ScriptSystem->OnDestory();
	m_PrefebManager->OnDestory();

}

void e2d::GameManager::OnFramebuffersize(const glm::ivec2& sz)
{
	if (m_SpriteRenderer)
		m_SpriteRenderer->SetScreenSize(sz);
}

void e2d::GameManager::SetScene(std::shared_ptr<e2d::Scene> scene)
{
#ifdef E2D_BUILD_TRANS
	m_TransformHandler->SetInst(scene);
#endif
#ifdef E2D_BUILD_RENDER
	m_SpriteRenderer->SetInst(scene);
#endif
#ifdef E2D_BUILD_AUDIO
	m_AudioSystem->SetInst(scene);
#endif
#ifdef E2D_BUILD_PHYSICS
	m_PhysicsSystem->SetInst(scene);
#endif
#ifdef E2D_BUILD_FUI

#endif

	m_ScriptSystem->SetInst(scene);
	m_PrefebManager->SetInst(scene);
}

void e2d::GameManager::SetTimerAndInput(e2d::Timer* timer, e2d::Input* input)
{
	m_Timer = timer;
	m_Input = input;
}


e2d::GameManager::~GameManager()
{
}
